<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="转换状态" prop="stateStr">
                <el-select v-model="queryParams.stateStr" placeholder="请选择">
                    <el-option label="成功" :value="1">
                    </el-option>
                    <el-option label="失败" :value="0">
                    </el-option>
                </el-select>
                <el-form-item label="文件名">
                    <el-input v-model="queryParams.filename"></el-input>
                </el-form-item>
                <el-form-item label="转换时间">
                    <el-date-picker v-model="valueTime" type="daterange" range-separator="至" start-placeholder="开始日期"
                        end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" @click="handleDelete">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" @click="handleExport">下载</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :search="false"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" :height="tableHeight - 19"
            border>
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="展示文件名" align="center" prop="fileName" :show-overflow-tooltip="true" />
            <el-table-column label="存贮文件名称" align="center" prop="serviceFileName" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column label="转换状态" align="center" prop="state" :show-overflow-tooltip="true">
            <template slot-scope="scope">
                {{ scope.row.state==1?'成功':'失败' }}
            </template>
            </el-table-column>
            <el-table-column label="转换时间" align="center" prop="transTime" :show-overflow-tooltip="true" />
            <el-table-column label="转换后路径" align="center" prop="transUrl" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column label="转换服务名称" align="center" prop="transType" :show-overflow-tooltip="true">
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
    </div>
</template>

<script>

import { list, deleteList } from "@/api/formatConversion/formatConversionList.js";
import estimateTableHeight from '@/mixins/estimateTableHeight';

export default {
    mixins: [estimateTableHeight], // 混入方法
    name: "Dict",
    dicts: ['sys_normal_disable'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            list: [],
            // 弹出层标题
            title: "",

            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                stateStr: "",
                filename: undefined,
                starttime:undefined,
                endtime:undefined
            },
            valueTime: "" //时间范围

        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询字典类型列表 */
        getList() {
            this.loading = true;
            list(this.queryParams).then(response => {
                this.list = response.rows;
                this.total = response.total;
                this.loading = false;
            }
            );
        },

        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.docId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },


        /** 删除按钮操作 */
        handleDelete(row) {
            // const dictIds = row.dictId || this.ids;
            if (!this.multiple) {
                this.$modal.confirm('是否确认删除所选数据项？').then(() => {
                    deleteList({
                        docId: this.ids.toString()
                    }).then(res => {
                        this.getList();
                        this.$modal.msgSuccess("删除成功");
                    })

                }).catch(() => { });
            } else {
                this.$message({ message: '只能选择要删除的数据!', type: 'warning' })
            }

        },
        /** 导出按钮操作 */
        handleExport() {
            if (this.queryParams.stateStr == '') {
                this.queryParams.stateStr = '-1'
            }
            this.download('/archive/toOfd/export', {
                ...this.queryParams
            }, `type_${new Date().getTime()}.xlsx`)
            this.queryParams.stateStr = ''
        },
        //搜索
        handleQuery() {
            console.log(this.valueTime)
            if(this.valueTime==null){
                this.queryParams.starttime=undefined;
                this.queryParams.endtime=undefined
            }else{
                this.queryParams.starttime=this.parseTime(this.valueTime[0],'{y}-{m}-{d}');
            this.queryParams.endtime=this.parseTime(this.valueTime[1],'{y}-{m}-{d}');
            }

            this.getList();
        },

        //重置
        resetQuery() {
            // this.$refs.queryForm.resetFields();
            this.queryParams.stateStr = ''
            this.valueTime=undefined
            this.queryParams.filename=undefined
            this.queryParams.starttime=undefined;
                this.queryParams.endtime=undefined
            this.getList();
        }
    }
};
</script>
